package com.gavin.export.utils;

import com.google.i18n.phonenumbers.PhoneNumberToCarrierMapper;
import com.google.i18n.phonenumbers.Phonenumber;
import com.google.i18n.phonenumbers.geocoding.PhoneNumberOfflineGeocoder;
import lombok.extern.slf4j.Slf4j;

import java.util.Locale;

/**
 * 数字串简单的混淆
 * @author admin
 */
@Slf4j
public class SimpleConfusion {

    private static Phonenumber.PhoneNumber phonenumber = getPhonenumberConf();

    /**
     * 根据手机号码获运营商
     * @param phoneNum
     * @return
     */
    public static String getOperator(String phoneNum){
        String operator = "";
        try{
            phonenumber.setNationalNumber(Long.parseLong(phoneNum));
            operator =  PhoneNumberToCarrierMapper.getInstance().getSafeDisplayName(phonenumber, Locale.CHINA);
        }catch (Exception e){
            log.error("根据手机号码获取加密信息 获取运营商，城市位置失败 {}",phoneNum,e);
        }

        return operator;
    }


    /**
     * 根据手机号码获取加密信息
     * @param phoneNum
     * @return
     */
    public static String getbelongingPlace(String phoneNum){
        String cityName = "";
        try{
            phonenumber.setNationalNumber(Long.parseLong(phoneNum));
            cityName = PhoneNumberOfflineGeocoder.getInstance().getDescriptionForValidNumber(phonenumber, Locale.CHINESE);
        }catch (Exception e){
            log.error("根据手机号码获取加密信息 获取运营商，城市位置失败 {}",phoneNum,e);
        }

        return cityName;
    }

    private static Phonenumber.PhoneNumber getPhonenumberConf(){
        Phonenumber.PhoneNumber phonenumber = new Phonenumber.PhoneNumber();
        phonenumber.setCountryCode(86);
        return phonenumber;
    }

    public static void main(String[] args) {
        String phone = "18629673060";
        System.out.println(getOperator(phone));
    }
}

